import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

class CommonPicker {
  static Future<int?> showPicker(BuildContext context, List<String> options, int value, {double height = 300}) {
    return showCupertinoModalPopup<int>(
        context: context,
        builder: (BuildContext context) {
          var controller = FixedExtentScrollController(initialItem: value);
          var buttonTextStyle = TextStyle(color: Theme.of(context).primaryColor, fontWeight: FontWeight.w600);
          return Container(
            color: Colors.grey[200],
            height: 300,
            child: Column(
              children: [
                SizedBox(
                  height: 40.0,
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      TextButton(
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          child: Text(
                            '取消',
                            style: buttonTextStyle,
                          )),
                      TextButton(
                          onPressed: () {
                            Navigator.of(context).pop(controller.selectedItem);
                          },
                          child: Text(
                            '确定',
                            style: buttonTextStyle,
                          ))
                    ],
                  ),
                ),
                Expanded(
                    child: CupertinoPicker(
                  scrollController: controller,
                  backgroundColor: Theme.of(context).scaffoldBackgroundColor,
                  itemExtent: 32.0,
                  onSelectedItemChanged: (val) {},
                  children: options
                      .map((item) => Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text(
                                item,
                                textAlign: TextAlign.center,
                                style: const TextStyle(fontSize: 18.0, fontWeight: FontWeight.w600),
                              )
                            ],
                          ))
                      .toList(),
                ))
              ],
            ),
          );
        });
  }
}
